home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / demo / medowl.zip / SOURCE / MEDT.H < prev    next >
C/C++ Source or Header  |  1994-08-18  |  13KB  |  402 lines

  1. #ifndef MAGMA
  2. #define MAGMA
  3. #endif
  4. //----------------------------------------------------------------------------
  5. // ObjectWindows - (C) Copyright 1991, 1993 by Borland International
  6. //   include\owl\edit.h
  7. //   Definition of class TEdit.  This defines the basic behavior
  8. //   of all edit controls.
  9. //----------------------------------------------------------------------------
  10. #if !defined(__OWL_MAGMAEDIT_H)
  11. #define __OWL_MAGMAEDIT_H
  12.  
  13. #if defined(MAGMA)
  14. #include <magmaed.h>
  15. #endif
  16.  
  17. #if !defined(__OWL_STATIC_H)
  18.   #include <owl\static.h>
  19. #endif
  20. #include <owl\edit.rh>
  21.  
  22. class _OWLCLASS TValidator;
  23.  
  24. //
  25. //  class TMagmaEdit
  26. //  ----- -----
  27. //
  28. class _OWLCLASS TMagmaEdit : public TStatic {
  29.   public:
  30.     TMagmaEdit(TWindow*   parent,
  31.           int             id,
  32.           const char far* text,
  33.           int x, int y, int w, int h,
  34.           UINT            textLen = 0,
  35.           BOOL            multiline = FALSE,
  36.           TModule*        module = 0);
  37.  
  38.     TMagmaEdit(TWindow*   parent,
  39.           int        resourceId,
  40.           UINT       textLen = 0,
  41.           TModule*   module = 0);
  42.  
  43.    ~TMagmaEdit();
  44.  
  45.     //
  46.     // Accessing
  47.     //
  48. #if defined(MAGMA)
  49.     LONG    GetNumLines() const;
  50.     int     GetLineLength(LONG lineNumber) const;
  51.     BOOL    GetLine(char far* str, int strSize, LONG lineNumber) const;
  52.     void    GetSubText(char far* str, DWORD startPos, DWORD endPos) const;
  53.     void    GetSelection(UINT& startPos, UINT& endPos) const;
  54.     void    ExGetSelection(LPCHARRANGE lpCharRange) const;
  55.     void    GetSelText(LPSTR lpBuf) const;
  56. #else
  57.     int     GetNumLines() const;
  58.     int     GetLineLength(int lineNumber) const;
  59.     BOOL    GetLine(char far* str, int strSize, int lineNumber) const;
  60.     void    GetSubText(char far* str, UINT startPos, UINT endPos) const;
  61.     void    GetSelection(UINT& startPos, UINT& endPos) const;
  62. #endif
  63.  
  64.     BOOL    IsModified() const;
  65.     void    ClearModify() {HandleMessage(EM_SETMODIFY);}
  66.  
  67. #if defined(MAGMA)
  68.     LONG    GetLineFromPos(DWORD charPos) const;
  69.     DWORD   GetLineIndex(LONG lineNumber) const;
  70. #else
  71.     int     GetLineFromPos(UINT charPos) const;
  72.     UINT    GetLineIndex(int lineNumber) const;
  73. #endif
  74.  
  75.     UINT    Transfer(void* buffer, TTransferDirection direction);
  76.  
  77.     //
  78.     // Lock and unlock this edit control's buffer. Allows direct access to the
  79.     // text in the edit control.
  80.     //
  81.     char far* LockBuffer(UINT newSize = 0);
  82.     void    UnlockBuffer(const char far* buffer, BOOL updateHandle = FALSE);
  83.  
  84.     //
  85.     // operations
  86.     //
  87. #if defined(MAGMA)
  88.     BOOL    DeleteSubText(DWORD startPos, DWORD endPos);
  89.     BOOL    DeleteLine(LONG lineNumber);
  90. #else
  91.     BOOL    DeleteSubText(UINT startPos, UINT endPos);
  92.     BOOL    DeleteLine(int lineNumber);
  93. #endif
  94.     BOOL    DeleteSelection();
  95.     BOOL    SetSelection(UINT startPos, UINT endPos);
  96. #if defined(MAGMA)
  97.     BOOL    ExSetSelection(LPCHARRANGE lpCharRange) const;
  98. #endif
  99.  
  100.     void    Scroll(int horizontalUnit, int verticalUnit);
  101.     void    Insert(const char far* str);
  102. #if defined(MAGMA)
  103.     LONG    Search(DWORD startPos, const char far* text,
  104. #else
  105.     int     Search(UINT startPos, const char far* text,
  106. #endif
  107.                    BOOL caseSensitive=FALSE, BOOL wholeWord=FALSE,
  108.                    BOOL up=FALSE);
  109.  
  110.     void    GetRect(TRect& frmtRect) const;
  111.     void    SetRect(const TRect& frmtRect);
  112.     void    SetRectNP(const TRect& frmtRect);
  113.     void    FormatLines(BOOL addEOL);
  114.     void    SetTabStops(int numTabs, const int far* tabs);
  115.  
  116.     HLOCAL  GetHandle() const;
  117.     void    SetHandle(HLOCAL localMem);
  118.  
  119.     void    SetPasswordChar(UINT ch) {HandleMessage(EM_SETPASSWORDCHAR, ch);}
  120.  
  121. #if defined(MAGMA)
  122.     LONG    GetFirstVisibleLine() const;
  123. #else
  124.     int     GetFirstVisibleLine() const;
  125. #endif
  126.     void    SetReadOnly(BOOL readOnly);
  127.     UINT    GetPasswordChar() const;
  128.  
  129.     EDITWORDBREAKPROC GetWordBreakProc() const;
  130.     void    SetWordBreakProc(EDITWORDBREAKPROC proc);
  131.  
  132.     //
  133.     // clipboard operations
  134.     //
  135.     BOOL    CanUndo() const;
  136.     void    EmptyUndoBuffer() {HandleMessage(EM_EMPTYUNDOBUFFER);}
  137.     void    Undo() {HandleMessage(WM_UNDO);}
  138.     void    Paste() {HandleMessage(WM_PASTE);}
  139.     void    Copy() {HandleMessage(WM_COPY);}
  140.     void    Cut() {HandleMessage(WM_CUT);}
  141.     
  142.     BOOL    IsValid(BOOL reportErr = FALSE);
  143.     void    SetValidator(TValidator* validator);
  144.     void    ValidatorError();
  145.  
  146.     //
  147.     // Override TStatic virtual member functions
  148.     //
  149.     void Clear();
  150.  
  151.   protected:
  152.     //
  153.     // command response functions
  154.     //
  155.     void    CmEditCut() {Cut();}                  // CM_EDITCUT
  156.     void    CmEditCopy() {Copy();}                // CM_EDITCOPY
  157.     void    CmEditPaste() {Paste();}              // CM_EDITPASTE
  158.     void    CmEditDelete() {DeleteSelection();}   // CM_EDITDELETE
  159.     void    CmEditClear() {Clear();}              // CM_EDITCLEAR
  160.     void    CmEditUndo() {Undo();}                // CM_EDITUNDO
  161.  
  162.     //
  163.     // command enabler functions
  164.     //
  165.     void CmSelectEnable(TCommandEnabler& commandHandler);
  166.     void CmPasteEnable(TCommandEnabler& commandHandler);
  167.     void CmCharsEnable(TCommandEnabler& commandHandler);
  168.     void CmModEnable(TCommandEnabler& commandHandler);
  169.  
  170.     //
  171.     // child id notification handled at the child
  172.     //
  173.     void    ENErrSpace();  // EN_ERRSPACE
  174.  
  175.     //
  176.     // Override TWindow virtual member functions
  177.     //
  178.     char far* GetClassName();
  179.     void      SetupWindow();
  180.  
  181.     //
  182.     // Input validation object
  183.     //
  184.     TValidator*  Validator;
  185.  
  186.     void         EvChar(UINT key, UINT repeatCount, UINT flags);
  187.     void         EvKeyDown(UINT key, UINT repeatCount, UINT flags);
  188.     UINT         EvGetDlgCode(MSG far*);
  189.     void         EvSetFocus(HWND hWndLostFocus);
  190.     void         EvKillFocus(HWND hWndGetFocus);
  191.     BOOL         CanClose();
  192.  
  193.     //
  194.     // handler for input validation message sent by parent
  195.     //
  196.     void         EvChildInvalid(HWND);
  197.  
  198.   private:
  199.     //
  200.     // hidden to prevent accidental copying or assignment
  201.     //
  202.     TMagmaEdit(const TMagmaEdit&);
  203.     TMagmaEdit& operator =(const TMagmaEdit&);
  204.  
  205.  
  206.     // Used to prevent 'oscillation' when a validated window with invalid
  207.     // input is losing focus to another validated window with invalid input
  208.     // Without this flag, the two windows will fight for focus
  209.     static TMagmaEdit* ValidatorReFocus;
  210.  
  211.   DECLARE_RESPONSE_TABLE(TMagmaEdit);
  212.   DECLARE_STREAMABLE(_OWLCLASS, TMagmaEdit, 1);
  213. };
  214.  
  215. //
  216. // edit control notification macros. methods are: void method()
  217. //
  218. // EV_EN_CHANGE(id, method)
  219. // EV_EN_ERRSPACE(id, method)
  220. // EV_EN_HSCROLL(id, method)
  221. // EV_EN_KILLFOCUS(id, method)
  222. // EV_EN_MAXTEXT(id, method)
  223. // EV_EN_SETFOCUS(id, method)
  224. // EV_EN_UPDATE(id, method)
  225. // EV_EN_VSCROLL(id, method)
  226.  
  227. //----------------------------------------------------------------------------
  228. // Inlines
  229. //----------------------------------------------------------------------------
  230.  
  231. //
  232. // returns the number of lines in the associated edit control
  233. //
  234. // note that GetNumLines returns 1 when the edit control has no text (i.e.
  235. // it has one line with no text in it). Returns zero if an error occurs
  236. //
  237. #if defined(MAGMA)
  238. inline LONG TMagmaEdit::GetNumLines() const {
  239.   return (LONG)CONST_CAST(TMagmaEdit*,this)->HandleMessage(EM_GETLINECOUNT);
  240. }
  241. #else
  242. inline int TMagmaEdit::GetNumLines() const {
  243.   return (int)CONST_CAST(TMagmaEdit*,this)->HandleMessage(EM_GETLINECOUNT);
  244. }
  245. #endif
  246.  
  247. inline BOOL TMagmaEdit::IsModified() const {
  248.   return (BOOL)CONST_CAST(TMagmaEdit*,this)->HandleMessage(EM_GETMODIFY);
  249. }
  250.  
  251. //
  252. // selects the characters in the range "startPos .. endPos"
  253. //
  254. inline BOOL TMagmaEdit::SetSelection(UINT startPos, UINT endPos) {
  255.   #if defined(__WIN32__)
  256.     return HandleMessage(EM_SETSEL, startPos, endPos) != 0;
  257.   #else
  258.     return HandleMessage(EM_SETSEL, 0, MAKELPARAM(startPos, endPos)) != 0;
  259.   #endif
  260. }
  261.  
  262. // returns the starting and ending positions of the selected text
  263. //
  264. inline void TMagmaEdit::GetSelection(UINT& startPos, UINT& endPos) const {
  265.   #if defined(__WIN32__)
  266.     CONST_CAST(TMagmaEdit*,this)->HandleMessage(EM_GETSEL, (WPARAM)&startPos, (LPARAM)&endPos);
  267.   #else
  268.     LRESULT  retValue = CONST_CAST(TMagmaEdit*,this)->HandleMessage(EM_GETSEL);
  269.     startPos = LOWORD(retValue);
  270.     endPos   = HIWORD(retValue);
  271.   #endif
  272. }
  273.  
  274. #if defined(MAGMA)
  275. inline BOOL TMagmaEdit::ExSetSelection(LPCHARRANGE charRange) const {
  276.     return (BOOL) CONST_CAST(TMagmaEdit*,this)->HandleMessage(EM_EXSETSEL, 0, (LPARAM) charRange) != 0;
  277. }
  278.  
  279. inline void TMagmaEdit::ExGetSelection(LPCHARRANGE charRange) const {
  280.     CONST_CAST(TMagmaEdit*,this)->HandleMessage(EM_EXGETSEL, 0, (LPARAM) charRange);
  281. }
  282.  
  283. inline void TMagmaEdit::GetSelText(LPSTR lpBuf) const {
  284.     CONST_CAST(TMagmaEdit*,this)->HandleMessage(EM_GETSELTEXT, 0, (LPARAM) lpBuf);
  285. }
  286. #endif
  287.  
  288.  
  289. //
  290. // returns the line number associated with character index "CharPos"
  291. //
  292. // if "CharPos" is greater than the number of characters, the last line is
  293. // returned
  294. // if "CharPos" is -1, the line containing the beginning of the selection (or
  295. // the line containing the caret if no selection) is returned
  296. //
  297. #if defined(MAGMA)
  298. inline LONG TMagmaEdit::GetLineFromPos(DWORD charPos) const {
  299.   return (LONG)CONST_CAST(TMagmaEdit*,this)->HandleMessage(EM_LINEFROMCHAR, 0, charPos);
  300. }
  301. #else
  302. inline int TMagmaEdit::GetLineFromPos(UINT charPos) const {
  303.   return (int)CONST_CAST(TMagmaEdit*,this)->HandleMessage(EM_LINEFROMCHAR, charPos);
  304. }
  305. #endif
  306.  
  307. //
  308. // returns the character index of line number "LineNumber" or -1 if
  309. // "LineNumber" is greater than the number of lines
  310. //
  311. // if "LineNumber" is -1, the line containing the caret is used
  312. //
  313. #if defined(MAGMA)
  314. inline DWORD TMagmaEdit::GetLineIndex(LONG lineNumber) const {
  315.   return (LONG)CONST_CAST(TMagmaEdit*,this)->HandleMessage(EM_LINEINDEX, 0, lineNumber);
  316. }
  317. #else
  318. inline UINT TMagmaEdit::GetLineIndex(int lineNumber) const {
  319.   return (int)CONST_CAST(TMagmaEdit*,this)->HandleMessage(EM_LINEINDEX, lineNumber);
  320. }
  321. #endif
  322.  
  323. //
  324. // scrolls the text by the specified horizontal and vertical amounts
  325. //
  326. inline void TMagmaEdit::Scroll(int horizUnit, int vertUnit) {
  327.   #if defined(__WIN32__)
  328.     HandleMessage(EM_LINESCROLL, horizUnit, vertUnit);
  329.   #else
  330.     HandleMessage(EM_LINESCROLL, 0, MAKELONG(vertUnit, horizUnit));
  331.   #endif
  332. }
  333.  
  334. //
  335. // sets the selection to the "str" (does a "paste" type of action
  336. // without affecting the clipboard)
  337. //
  338. inline void TMagmaEdit::Insert(const char far* str) {
  339.   HandleMessage(EM_REPLACESEL, 0, (LPARAM)str);
  340. }
  341.  
  342. inline void TMagmaEdit::GetRect(TRect& frmtRect) const {
  343.   CONST_CAST(TMagmaEdit*,this)->HandleMessage(EM_GETRECT, 0, (LPARAM)(TRect FAR*)&frmtRect);
  344. }
  345.  
  346. inline void TMagmaEdit::SetRect(const TRect& frmtRect) {
  347.   HandleMessage(EM_SETRECT, 0, (LPARAM)(const TRect FAR*)&frmtRect);
  348. }
  349.  
  350. inline void TMagmaEdit::SetRectNP(const TRect& frmtRect) {
  351.   HandleMessage(EM_SETRECTNP, 0, (LPARAM)(const TRect FAR*)&frmtRect);
  352. }
  353.  
  354. inline void TMagmaEdit::FormatLines(BOOL addEOL) {
  355.   HandleMessage(EM_FMTLINES, addEOL);
  356. }
  357.  
  358. inline void TMagmaEdit::SetTabStops(int numTabs, const int far* tabs) {
  359.   HandleMessage(EM_SETTABSTOPS, numTabs, (LPARAM)tabs);
  360. }
  361.  
  362. inline HLOCAL TMagmaEdit::GetHandle() const {
  363.   return (HLOCAL)CONST_CAST(TMagmaEdit*,this)->HandleMessage(EM_GETHANDLE);
  364. }
  365.  
  366. inline void TMagmaEdit::SetHandle(HLOCAL localMem) {
  367.   HandleMessage(EM_SETHANDLE, (WPARAM)localMem);
  368. }
  369.  
  370. #if defined(MAGMA)
  371. inline LONG TMagmaEdit::GetFirstVisibleLine() const {
  372.   return (LONG)CONST_CAST(TMagmaEdit*,this)->HandleMessage(EM_GETFIRSTVISIBLELINE);
  373. }
  374. #else
  375. inline int TMagmaEdit::GetFirstVisibleLine() const {
  376.   return (int)CONST_CAST(TMagmaEdit*,this)->HandleMessage(EM_GETFIRSTVISIBLELINE);
  377. }
  378. #endif
  379.  
  380. inline void TMagmaEdit::SetReadOnly(BOOL readOnly) {
  381.   HandleMessage(EM_SETREADONLY, readOnly);
  382. }
  383.  
  384. inline UINT TMagmaEdit::GetPasswordChar() const {
  385.   return (UINT)CONST_CAST(TMagmaEdit*,this)->HandleMessage(EM_GETPASSWORDCHAR);
  386. }
  387.  
  388. inline EDITWORDBREAKPROC TMagmaEdit::GetWordBreakProc() const {
  389.   return (EDITWORDBREAKPROC)CONST_CAST(TMagmaEdit*,this)->HandleMessage(EM_GETWORDBREAKPROC);
  390. }
  391.  
  392. inline void TMagmaEdit::SetWordBreakProc(EDITWORDBREAKPROC proc) {
  393.   HandleMessage(EM_SETWORDBREAKPROC, 0, (LPARAM)proc);
  394. }
  395.  
  396. inline BOOL TMagmaEdit::CanUndo() const {
  397.   return (BOOL)CONST_CAST(TMagmaEdit*,this)->HandleMessage(EM_CANUNDO);
  398. }
  399.  
  400. #endif  // __OWL_MAGMAEDIT_H
  401.  
  402.